import itertools

# 输入数组
input_list = [i for i in range(1, 28) if i % 3 == 0]

# 生成所有可能的排列
permutations = list(itertools.permutations(input_list))

def create_square(perm):
    # 从排列创建一个3x3数组
    return [perm[i*3:i*3+3] for i in range(3)]

def check_magic_square(square):
    # 检查数组是否符合条件
    target_sum = sum(square[0])
    for i in range(3):
        if sum(square[i]) != target_sum or sum([row[i] for row in square]) != target_sum:
            return False
    if square[0][0] + square[1][1] + square[2][2] != target_sum or square[0][2] + square[1][1] + square[2][0] != target_sum:
        return False
    return True

# 检查所有的排列
valid_squares = []
for perm in permutations:
    square = create_square(perm)
    if check_magic_square(square):
        valid_squares.append(square)

# 打印所有符合条件的数组
for square in valid_squares:
    print(square)
